<script setup>
import {ref} from "vue";
import request9191 from "../../../utils/request9191.js";
import {ElMessage, ElMessageBox} from "element-plus";
import {Delete} from "@element-plus/icons-vue";
//我的社团成员
const clubPeopleData = ref();
const findClubPeople = ref({
  cClub:"",
  sName:""
})

let pageNum = 1
let pageSize = 5
const total = ref(0)

const handleSizeChange = (val) => {
  pageSize = val
  getClubPeople()
}
const handleCurrentChange = (val) => {
  pageNum = val
  getClubPeople()
}
//获取本社团的所有成员
const getClubPeople = () => {
  request9191({
    url: '/clubJoin/page',
    method: 'get',
    params: {
      page:pageNum,
      pageSize:pageSize,
      cClub:findClubPeople.value.cClub?findClubPeople.value.cClub:null,
      sName:findClubPeople.value.sName?findClubPeople.value.sName:null
    }
  }).then((res)=>{
    clubPeopleData.value = res.data.data.rows
    total.value = res.data.data.total
  })
}


//管理员删除学生
const DeleteStudent = (id) => {
  ElMessageBox.confirm(
      '确认删除该名学生?',
      '温馨提示',
      {
        confirmButtonText:'确认',
        cancelButtonText:'取消',
        type:'warning'
      }
  )
      .then(()=>{
        request9191({
          url:'clubJoin',
          method:'delete',
          params:{
            id:id
          }
        }).then(() =>{
          ElMessage.success('删除成功')
          getMyStudent()
        })
      }).catch(() =>{
    ElMessage({
      type:'info',
      message:'已取消'
    })
  })
}

getClubPeople()
</script>

<template>
  <div class="MyPeople">
    <el-form :inline="true" :model="findClubPeople" class="demo-form-inline">
      <el-form-item label="社团名称">
        <el-input v-model="findClubPeople.cClub" placeholder="输入名称" clearable/>
      </el-form-item>
      <el-form-item label="学生姓名">
        <el-input v-model="findClubPeople.sName" placeholder="输入姓名" clearable/>
      </el-form-item>
      <el-button type="primary" @click="getClubPeople">搜索</el-button>
    </el-form>
    <el-card>
    <el-table :data="clubPeopleData" style="width: 100%" border="border">
      <el-table-column prop="id" label="ID"/>
      <el-table-column prop="sname" label="学生姓名"/>
      <el-table-column prop="sclass" label="班级"/>
      <el-table-column prop="sgender" label="性别"/>
      <el-table-column prop="sphone" label="电话"/>
      <el-table-column prop="cname" label="所属社团"/>
      <el-table-column prop="ctype" label="社团类型"/>
      <el-table-column prop="cheader" label="社团团长"/>
      <el-table-column label="状态" width="100px">
        <template #default="scope">
          <el-tag v-if="scope.row.status === 0" type="warning">待审核</el-tag>
          <el-tag v-else-if="scope.row.status === 1" type="success">已通过</el-tag>
          <el-tag v-else type="danger">已驳回</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="cJoinTime" label="加入时间"/>

      <el-table-column label="操作" width="150px">
        <template #default="scope">
          <el-button size="default" type="danger" @click="DeleteStudent(scope.row.id)">
            <el-icon><Delete /></el-icon>
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    </el-card>

<!--  分页-->
    <el-pagination background layout="prev,sizes, pager, next"
                   :page-sizes="[5,10]"
                   :total="total"
                   :page-size="pageSize"
                   @size-change="handleSizeChange"
                   @current-change="handleCurrentChange"

    />
  </div>
</template>

<style scoped>

</style>